package cn.bopomo.dealer.uloo.action;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.bopomo.dealer.base.action.BaseAction;
import cn.bopomo.dealer.base.util.Page;
import cn.bopomo.dealer.uloo.common.UlooConstant;
import cn.bopomo.dealer.uloo.service.impl.UlooBackStageServiceImpl;

import java.util.GregorianCalendar;
import java.util.HashMap;


public class ShowGuestbookListAction extends BaseAction {

	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		response.setContentType("text/html;charset=UTF-8");
		response.setHeader("Cache-control","no-cache");
		
		//判断权限
		if (!this.hasPermission(request)){
			//error
			response.getWriter().write("errors:你没有权限进行该操作");
			return null;
		}
		
//		GregorianCalendar gg = new GregorianCalendar ();
		
//		//获取当前操作员ID
//		String userId = this.getUserId(request);
//		if(userId == null){
//			return this.findFailure(mapping);
//		}
		//获取当前分页数
		String strPageSize = request.getParameter("pageSize");
		if (strPageSize == null || "".equals(strPageSize)){
			strPageSize = "1";
		}
		//获取起止时间
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		//获取service
//		UlooBackStageServiceImpl service = (IOperatorService)this.findService(ServiceConfig.OPERATOR_SERVICE);
		UlooBackStageServiceImpl service = new UlooBackStageServiceImpl();
		//获取查询列表
		Page resultPage = service.showGuestBookList(
									Integer.parseInt(strPageSize), 
									UlooConstant.LIST_PAGE_DEFAULT_ROWS, 
									startDate, 
									endDate);
		//设置分页查询的提交URL
		if (resultPage != null && resultPage.getList().size()>0){
			resultPage.setTarget(request.getRequestURI());
		}
		//设置对象并返回
		request.setAttribute(UlooConstant.KEY_GUEST_BOOK_LIST_PAGE,resultPage);
		return this.findSuccess(mapping);
		
	}
	
	protected boolean isValidateData(String regEx, String str){
		Pattern pattern= Pattern.compile(regEx);
		Matcher m=pattern.matcher(str); 
		
		return m.find();
	}
	
	public static void  main(String[] sa){
		//CheckWowCardAction ca = new CheckWowCardAction();
		//System.out.println(ca.isValidateData(ca.REGEX_DATE,"2007-02-29"));
	}
}
